package odgs.message.server;

import java.util.HashMap;

import odgs.Connection;
import odgs.Result;
import odgs.message.Message;
import odgs.message.MessageHandler;
import odgs.message.MessageProcessor;
import odgs.transaction.ContentsAddTransaction;

public class ContentsAddedCompleteHandler implements MessageHandler
{
	public void execute(MessageProcessor processor, Message msg, Connection con) 
	{
		ContentsAddTransaction tran =  (ContentsAddTransaction) msg.get("transaction");
		
		Message reMsg = new Message();
		reMsg.setResult(Result.CONTENTS_ADDED_OK);
		reMsg.setName(Message.CONTENTS_ADD_TRANSACTION_RESPONSE);

		int pk = processor.getServerManager().getContentsPK(tran.getSource());
		tran.getSource().setUid(pk);
		reMsg.put("state", processor.getServerManager().getGridState());
		reMsg.put("transaction", tran);

		processor.getNetworkManager().broadcastMessage(reMsg);
	}	
}
